package ca.vane.windsock;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

public class CurrentConditions {
  public CurrentConditions(String data_url, Proxy proxy) throws Exception
  {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    
    Document doc;
    try {
      DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
      URL url = new URL(data_url);
      HttpURLConnection http = (HttpURLConnection)url.openConnection(proxy);
      http.setReadTimeout(10000);
      http.setConnectTimeout(10000);
      http.setRequestMethod("GET");
      http.setDoOutput(true);
      http.connect();
      InputStream stream = http.getInputStream();
      doc = docBuilder.parse(stream);
    } catch (ParserConfigurationException e) {
      throw new Exception(e);
    } catch (MalformedURLException e) {
      throw new Exception(e);
    }
       
    System.out.println(doc.getDocumentElement().getNodeName());
  }

}
